import request from '@/config/axios'
import type { Dayjs } from 'dayjs'

/** crm发票抬头信息 */
export interface ReceiptTitle {
  id: number // id
  titleType: number // 抬头类型
  title: string // 发票抬头
  taxCode: string // 纳税人识别号
  bankName: string // 开户行
  bankAccount: string // 开户行账号
  receiptAddress: string // 开票地址
  phoneNumber: string // 电话号码
  ownerUserId: number // 负责人的用户编号
}

// crm发票抬头 API
export const ReceiptTitleApi = {
  // 查询crm发票抬头分页
  getReceiptTitlePage: async (params: any) => {
    return await request.get({ url: `/crm/receipt-title/page`, params })
  },

  // 查询crm发票抬头详情
  getReceiptTitle: async (id: number) => {
    return await request.get({ url: `/crm/receipt-title/get?id=` + id })
  },

  // 新增crm发票抬头
  createReceiptTitle: async (data: ReceiptTitle) => {
    return await request.post({ url: `/crm/receipt-title/create`, data })
  },

  // 修改crm发票抬头
  updateReceiptTitle: async (data: ReceiptTitle) => {
    return await request.put({ url: `/crm/receipt-title/update`, data })
  },

  // 删除crm发票抬头
  deleteReceiptTitle: async (id: number) => {
    return await request.delete({ url: `/crm/receipt-title/delete?id=` + id })
  },

  /** 批量删除crm发票抬头 */
  deleteReceiptTitleList: async (ids: number[]) => {
    return await request.delete({ url: `/crm/receipt-title/delete-list?ids=${ids.join(',')}` })
  },

  // 导出crm发票抬头 Excel
  exportReceiptTitle: async (params) => {
    return await request.download({ url: `/crm/receipt-title/export-excel`, params })
  }
}

export const getReceiptTitleList = (customerId: number): Promise<ReceiptTitle[]> => {
  return request.get({ url: '/crm/receipt-title/simple-all-list?customerId=' + customerId })
}
